package com.h5ve.flow.adapter;

import com.h5ve.base.constant.CommonConstants;
import com.h5ve.security.entity.H5veUser;
import com.warm.flow.core.enums.CooperateType;
import com.warm.flow.core.service.TaskService;
import com.warm.flow.core.utils.StreamUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public abstract class AbstractWarmFlowAdapter {
    @Resource
    protected TaskService taskService;

    /**
     * 获取权限
     *
     * @return 权限列表
     */
    protected List<String> permissionList(H5veUser sysUser) {
        List<String> permissionList = StreamUtils.toList(new ArrayList<>(sysUser.getRoles()), role -> "role:" + role.replace(CommonConstants.ROLE, ""));
        permissionList.add(String.valueOf(sysUser.getId()));
        permissionList.add("dept:" + sysUser.getDeptId());
        return permissionList;
    }

    /**
     * 根据类型获取描述
     *
     * @param type 流程类型
     * @return value
     */
    protected String type(Integer type) {
        return CooperateType.getValueByKey(type);
    }
}
